<?php

namespace App\Http\Controllers\Backend\Rotation;

use Illuminate\Http\Request;
use App\Http\Models\Rotation\RotationFrom;
use App\Http\Models\Rotation\RotationService;
use App\Http\Controllers\Backend\BackendController;

class RotationController extends BackendController
{

    /**
     * RotationController  轮播图
     *
     * @author Jinfeihu
     * 
     * */
    private $rotationService;
    private $request;

    public function __construct(RotationService $rotationService, Request $request) {
        $this->rotationService = $rotationService;
        $this->request = $request;
    }

    public function index() {
        $rotationDatas = $this->rotationService->index($this->request);
        return view("backend.rotation.index", [
            'rotationDatas' => $rotationDatas,
            'request' => $this->request
        ]);
    }

    public function create() {
        //$datas = $this->rotaionService->getRule();
        return view("backend.rotation.create");
    }

    public function store(RotationFrom $rotaionFrom) {
        $this->rotationService->store($rotaionFrom);
        return redirect('admin/rotation');
    }

    public function edit($id) {
        $rotaionDatas = $this->rotationService->show($id);
        return view('backend.rotation.update', [
            'rotationData' => $rotaionDatas
        ]);
    }

    public function update(RotationFrom $rotaionFrom, $id) {
        $this->rotationService->updateSave($rotaionFrom, $id);
        return redirect('admin/rotation');
    }
    
    public function destroy($id) {
        return $this->rotationService->remove($id);
    }

}
